package slcu.inscripcion;

import java.io.IOException;

import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletSession;
import javax.portlet.PortletSessionUtil;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import com.liferay.portal.kernel.util.ParamUtil;

public class ResourceController {
	
	private ResourceRequest request;
	private ResourceResponse response;
	private PortletContext pc; 
	private static String ESCUELA_COMBO_JSP = "/html/inscripcion/snippets/escuela_combo.jsp";
	
	public ResourceController(ResourceRequest resourceRequest, 
			                  ResourceResponse resourceResponse, 
			                  PortletContext portletContext) {
		request = resourceRequest;
		response = resourceResponse;
		pc = portletContext;		
	}
	
	public void escuelasByRegionCombo() throws PortletException, IOException {
		
		String region = ParamUtil.getString(request, "region");
		request.setAttribute("region", region);
		String escuela = ParamUtil.getString(request, "escuela");
		request.setAttribute("escuela", escuela);
		
	    PortletRequestDispatcher dispatcher = pc.getRequestDispatcher(ESCUELA_COMBO_JSP);
		dispatcher.include(request, response);
		
	}
	
	public void deportistasByRegionEscuelaTable() throws PortletException, IOException {
		
		PortletSession ps = request.getPortletSession();
		String region = ParamUtil.getString(request, "region");
		request.setAttribute("region", region);
		ps.setAttribute("region", region);
		String escuela = ParamUtil.getString(request, "escuela");
		request.setAttribute("escuela", escuela);
		ps.setAttribute("escuela", escuela);
		String jspPage = ParamUtil.getString(request, "jspPage");
		
		if (!jspPage.isEmpty()) {
		    PortletRequestDispatcher dispatcher = pc.getRequestDispatcher(jspPage);
			dispatcher.include(request, response);
		}
	} 

}
